# CMake最低版本要求
cmake_minimum_required(VERSION 3.10)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
# 工程名称
project(osapi)
# 当前目录
message("CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
# 导出符号
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    add_definitions(-DOS_EXPORT_DLL)
endif()
add_definitions(-DOS_EXPORT)

# 源代码
# TODO: 此库尚未编写完成，因此只编译有用部分
file(GLOB OS_API_H
        ${CMAKE_CURRENT_SOURCE_DIR}/../../include/osapi/osapi.h
        ${CMAKE_CURRENT_SOURCE_DIR}/../../include/osapi/osplatform.h)
file(GLOB OS_API_CPP
        ${CMAKE_CURRENT_SOURCE_DIR}/libc.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/osplatform.cpp)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    add_definitions(-DWIN32_PC)
    file(GLOB OS_API_CPP
            ${OS_API_CPP}
            ${CMAKE_CURRENT_SOURCE_DIR}/win32file.cpp
         )
    aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/windows PlatformSRCS)
    set(OS_API_CPP ${OS_API_CPP} ${PlatformSRCS})
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
    add_definitions(-DANDROID)
    file(GLOB OS_API_CPP
            ${OS_API_CPP}
            ${CMAKE_CURRENT_SOURCE_DIR}/androidfile.cpp)
    aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/android PlatformSRCS)
    set(OS_API_CPP ${OS_API_CPP} ${PlatformSRCS})
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "iOS")
    add_definitions(-DIOS)
    file(GLOB OS_API_CPP
            ${OS_API_CPP}
            ${CMAKE_CURRENT_SOURCE_DIR}/iphonefile.mm
            ${CMAKE_CURRENT_SOURCE_DIR}/iphonenetwork.mm
            ${CMAKE_CURRENT_SOURCE_DIR}/iphonehttp.h
            ${CMAKE_CURRENT_SOURCE_DIR}/iphonehttp.mm
            // TO DO : HYM
            # ${CMAKE_CURRENT_SOURCE_DIR}/iphonetts.h
            # ${CMAKE_CURRENT_SOURCE_DIR}/iphonetts.mm
            # ${CMAKE_CURRENT_SOURCE_DIR}/iphonewaveplayer.h
            # ${CMAKE_CURRENT_SOURCE_DIR}/iphonewaveplayer.mm
            # ${CMAKE_CURRENT_SOURCE_DIR}/iphonesound.mm
            )
    aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/ios PlatformSRCS)
    set(OS_API_CPP ${OS_API_CPP} ${PlatformSRCS})
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
    add_definitions(-DMAC)
    file(GLOB OS_API_CPP
            ${OS_API_CPP}
            ${CMAKE_CURRENT_SOURCE_DIR}/iphonefile.mm)
    set(OS_API_CPP ${OS_API_CPP} ${PlatformSRCS})
else()
    add_definitions(-DUNIX_LIKE)
    file(GLOB OS_API_CPP
            ${OS_API_CPP}
            ${CMAKE_CURRENT_SOURCE_DIR}/stdfile.cpp)
    aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/unix PlatformSRCS)
    set(OS_API_CPP ${OS_API_CPP} ${PlatformSRCS})
endif()

set(SOURCE_CODE ${OS_API_H} ${OS_API_CPP})
message("OSAPI SOURCE_CODE: " ${SOURCE_CODE})

# 创建动态库
add_library(osapi STATIC ${SOURCE_CODE})